/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package session01;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author sinhnx <sinhnx@fpt.aptech.ac.vn>
 */
public class InsertSubjects {

    public static void main(String[] args) {

        String url = "jdbc:sqlserver://192.168.1.51:1433;databaseName=APJII_DB;user=sinhnx;password=fat123456";
        try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

            Connection cn = DriverManager.getConnection(url);

//            PreparedStatement pstm = cn.prepareStatement("﻿INSERT INTO Subjects VALUES(?,?,?,?)");
            PreparedStatement pstm = cn.prepareStatement("﻿﻿INSERT INTO Subjects VALUES('APJ2', 'Advance Programing Java 2', 9, 9)");

//            pstm.setString(1, "APJ2");
//            pstm.setString(2, "Advance Programing Java 2");
//            pstm.setInt(3, 5);
//            pstm.setInt(4, 5);

            int count = pstm.executeUpdate();
            if (count > 0) {
                System.out.println("Co " + count + "hang duoc cap nhat");
            }

            pstm.close();

            cn.close();
        } catch (SQLException ex) {
            Logger.getLogger(JDBC_ODBC.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(JDBC_ODBC.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
